﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Data;

namespace WebSys.UI
{
    public partial class ZJ_KHSQPage : Page
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        #region 页面元素
        protected global::System.Web.UI.HtmlControls.HtmlForm form1;
        protected global::System.Web.UI.WebControls.TextBox txt开户理由;
        protected global::System.Web.UI.WebControls.Button Button1;
        protected global::System.Web.UI.WebControls.Label 申请开户理由1;
        protected global::System.Web.UI.WebControls.TextBox txt领导意见;
        protected global::System.Web.UI.WebControls.Button Button2;
        protected global::System.Web.UI.WebControls.Button Button3;
        protected global::System.Web.UI.WebControls.Label 领导意见1;
        protected global::System.Web.UI.WebControls.TextBox txt开户理由1;
        protected global::System.Web.UI.WebControls.Button Button4;
        protected global::System.Web.UI.HtmlControls.HtmlTable table1;
        protected global::System.Web.UI.HtmlControls.HtmlTable table2;
        protected global::System.Web.UI.HtmlControls.HtmlTable table3;
        protected global::System.Web.UI.HtmlControls.HtmlTable table4;
        protected global::System.Web.UI.WebControls.Label Label1;
        protected global::System.Web.UI.WebControls.Label Label2;
        protected global::System.Web.UI.WebControls.Label Label3;
        protected global::System.Web.UI.HtmlControls.HtmlTableRow tr1;
        protected global::System.Web.UI.HtmlControls.HtmlTableRow tr2;
        #endregion
        public string strBCId = string.Empty;
        public string strPid = string.Empty;
        public string action = string.Empty;
        public string userId = string.Empty;
        public string strType = string.Empty;
        public string strID = string.Empty;
        public string fromsrc = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (Session["UserID"] != null) { userId = Session["UserID"].ToString(); }
            strBCId = Request["bcid"];
            strPid = Request["PID"];
            strType = Request["type"];
            strID = Request["ID"];
            fromsrc = Request["fromsrc"];
            string csql = "select count(*) from ZS_ZJKHSQ where  PID='" + strPid + "'";
            string sql1 = "select 开户审核状态 from ZS_ZJKHSQ where PID='" + strPid + "' order by addtime desc";
            action = _EluZSDataProvider.GetSomeStr("(" + sql1 + ")", "*", "");
            
            if (!string.IsNullOrEmpty(strType) && strType == "view")
            {
                if (!string.IsNullOrEmpty(strID))
                {
                    table4.Visible = true;
                    string sql = "select 申请理由 from ZS_ZJKHSQ t where id='" + strID + "'";
                    string sqly = _EluZSDataProvider.GetSomeStr("(" + sql + ")", "*", "");
                    string sql2 = "select 批复意见 from ZS_ZJKHSQ t where id='" + strID + "'";
                    string pfyj = _EluZSDataProvider.GetSomeStr("(" + sql2 + ")", "*", "");
                    if (!string.IsNullOrEmpty(sqly)) { tr1.Visible = true; Label1.Text = sqly; }
                    if (!string.IsNullOrEmpty(pfyj)) { tr2.Visible = true; Label2.Text = pfyj; }
                }

            }
            else {
                if (!string.IsNullOrEmpty(action))
                {
                    if (action == "0")
                    {
                        table1.Visible = true;
                    }
                    else if (action == "1")
                    {
                        if (fromsrc == "bld")
                        {
                            table2.Visible = true;
                            string sql = @"select 申请理由 from ZS_ZJKHSQ where PID='" + strPid + @"' 
                    and 开户审核状态=1 order by addtime desc";
                            申请开户理由1.Text = _EluZSDataProvider.GetSomeStr("(" + sql + ")", "*", "");
                        }
                        else {
                            Label3.Text = "开户申请已传至办领导处！";
                        }
                    }
                    else if (action == "2")
                    {
                        if (fromsrc == "zjk")
                        {
                            table3.Visible = true;
                            string sql = @"select 批复意见 from ZS_ZJKHSQ where PID='" + strPid + @"' 
                    and 开户审核状态=2 order by addtime desc ";
                            领导意见1.Text = _EluZSDataProvider.GetSomeStr("(" + sql + ")", "*", "");
                        }
                        else
                        {
                            Label3.Text = "开户申请已打回到资金科！";
                        }
                    }
                    else if (action == "3")
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "a", "<script>getallover();</script>");
                    }
                }
                else
                {
                    table1.Visible = true;
                }
            }
        }
        /*--再次申请 2→1--*/
        protected void Button4_Click(object sender, EventArgs e)
        {
            string zckhly = txt开户理由1.Text.Trim();
            if (!string.IsNullOrEmpty(zckhly))
            {
                string sql = string.Format(@"insert into ZS_ZJKHSQ (申请理由,BCID,PID,USERID,开户审核状态) values 
('{0}','{1}','{2}','{3}','1')", zckhly, strBCId, strPid, userId);
                _EluZSDataProvider.RunSqlNon(sql);
                sql = "update ZS_BCBASICINFO set 开户审核状态=1 where id ='" + strBCId + "'";
                _EluZSDataProvider.RunSqlNon(sql);
                Antu.Utilities.UtilitiesPage.AlertDialog("再次申请成功！", "window.close();");
            }
        }
        /*--退回申请 1→2--*/
        protected void Button3_Click(object sender, EventArgs e)
        {
            string ldyj = txt领导意见.Text.Trim();
            if (!string.IsNullOrEmpty(ldyj))
            {
                string sql = string.Format(@"insert into ZS_ZJKHSQ (批复意见,BCID,PID,USERID,开户审核状态) values 
('{0}','{1}','{2}','{3}','2')", ldyj, strBCId, strPid, userId);
                _EluZSDataProvider.RunSqlNon(sql);
                sql = "update ZS_BCBASICINFO set 开户审核状态=2 where id ='" + strBCId + "'";
                _EluZSDataProvider.RunSqlNon(sql);
                Antu.Utilities.UtilitiesPage.AlertDialog("已退回！", "window.close();");
            }
        }
        /*--确认通过申请 1→3--*/
        protected void Button2_Click(object sender, EventArgs e)
        {
            string ldyj = txt领导意见.Text.Trim();
            if (!string.IsNullOrEmpty(ldyj))
            {
                string sql = string.Format(@"insert into ZS_ZJKHSQ (批复意见,BCID,PID,USERID,开户审核状态) values 
('{0}','{1}','{2}','{3}','3')", ldyj, strBCId, strPid, userId);
                _EluZSDataProvider.RunSqlNon(sql);
                sql = "update ZS_BCBASICINFO set 开户审核状态=3 where id ='" + strBCId + "'";
                _EluZSDataProvider.RunSqlNon(sql);

                //string update = @"update ZS_BCBASICINFO set 开户审核状态=3 where id ='" + strBCId + "'";
                Antu.Utilities.UtilitiesPage.AlertDialog("确认通过申请！", "window.close();");
            }
        }
        /*--初次申请 0→1--*/
        protected void Button1_Click(object sender, EventArgs e)
        {
            string khly = txt开户理由.Text.Trim();
            if (!string.IsNullOrEmpty(khly))
            {
                string sql = string.Format(@"insert into ZS_ZJKHSQ (申请理由,BCID,PID,USERID,开户审核状态,是否初次) values 
('{0}','{1}','{2}','{3}','1','1')", khly, strBCId, strPid, userId);
                _EluZSDataProvider.RunSqlNon(sql);
                //sql = "update ZS_BCBASICINFO set 开户审核状态=1 where id ='" + strBCId + "'";
                //_EluZSDataProvider.RunSqlNon(sql);

                //if ()
                if (!ISexitProject(strPid))
                {
                    string id = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                    string insertsql = @"insert into zs_bcbasicinfo (ID, PNID, 报结情况, 征收实施单位, 
划转金额, 开户银行, 存折户数, 评估总补偿款, 存折金额, 到账金额, 银行账号, 余额, 
时间, 备注, 说明, 征收部门, 开户审核状态)
 select '" + id + "' ID,'" + strPid + "' PNID,(select 报结情况 from ZS_BCBASICINFO where pnid ='" + strPid + "') 报结情况," + @"
                    (select 征收实施单位 from ZS_BCBASICINFO where pnid ='" + strPid + "') 征收实施单位," + @"
                    (select 划转金额 from ZS_BCBASICINFO where pnid ='" + strPid + "') 划转金额, " + @"
                    (select 开户银行 from ZS_BCBASICINFO where pnid ='" + strPid + "') 开户银行, " + @"
                    (select 存折户数 from ZS_BCBASICINFO where pnid ='" + strPid + "') 存折户数, " + @"
                    (select 评估总补偿款 from ZS_BCBASICINFO where pnid ='" + strPid + "') 评估总补偿款, " + @"
                    (select 存折金额 from ZS_BCBASICINFO where pnid ='" + strPid + "') 存折金额, " + @"
                    (select 到账金额 from ZS_BCBASICINFO where pnid ='" + strPid + "') 到账金额, " + @"
                    (select 银行账号 from ZS_BCBASICINFO where pnid ='" + strPid + "') 银行账号, " + @"
(select 余额 from ZS_BCBASICINFO where pnid ='" + strPid + "') 余额, " + @"
(select 时间 from ZS_BCBASICINFO where pnid ='" + strPid + "') 时间, " + @"
(select 备注 from ZS_BCBASICINFO where pnid ='" + strPid + "') 备注, " + @"
(select 说明 from ZS_BCBASICINFO where pnid ='" + strPid + "') 说明, " + @"
(select 征收部门 from ZS_BCBASICINFO where pnid ='" + strPid + "') 征收部门, " + @"
'1' 开户审核状态 from dual";
                    _EluZSDataProvider.RunSqlNon(insertsql);

                    string upbckjbsql = @"update zs_zjkhsq set bcid='" + id + "' where pid = '" + strPid + "'";
                    _EluZSDataProvider.RunSqlNon(upbckjbsql);
                }
                Antu.Utilities.UtilitiesPage.AlertDialog("开户申请成功！", "window.close();");
            }
        }

        public bool ISexitProject(string pid)
        {
            bool b = false;
            string sql = @"select id from zs_bcbasicinfo where pnid = '" + pid + "'";
            string id = _EluZSDataProvider.GetSomeStr("(" + sql + ")", "*", "");
            if (!string.IsNullOrEmpty(id))
            {
                b = true;
            }
            return b;
        }
    }
}


